﻿using UnityEngine;
using System.Collections;
using System.IO;

public class Image : MonoBehaviour {

    public UILabel INFilePath;
    public UILabel InnewFilePath;
    public UILabel INtianjiaString;


    //public string FilePath;
    //public string newFilePath;
    //public string tianjiaString;
   

    public void StartOnclike()
    {
        string FilePath = INFilePath.text;
        string newFilePath = InnewFilePath.text;
        string tianjiaString = INtianjiaString.text;

        string[] files = Directory.GetFiles(FilePath);

        DirectoryInfo folder = new DirectoryInfo(FilePath);
        FileInfo[] infos = folder.GetFiles("*.jpg");

        for (int i = 0; i < infos.Length; i++)
        {

            int info = (int)Mathf.Sqrt(infos.Length);

            //string oldname =  files[i].Replace(@"\\",@"\");

            string newname = newFilePath + @"\" + tianjiaString + "_" + infos[i].Name;
            //string newname = newFilePath + @"\" + tianjiaString +"_"+ i / info + "_" + i % info + ".jpg";
            //File.Move(oldname, newname);
            File.Move(files[i], newname);
            //file.MoveTo(FilePath + @"\\" + newname);
        }

    }

    public void Exit()
    {
        Application.Quit();
    }

    //void Start () {
        //File.
       //string[] files=Directory.GetFiles(FilePath);

       // DirectoryInfo folder = new DirectoryInfo(FilePath);
       // FileInfo[] infos = folder.GetFiles("*.jpg");
       //// for (int i = 0; i <= files.Length; i++)
       //// {
       ////     FileStream file = File.Create(files[i]);

       // //     File.
       // // }

       // //第二种方法 

       // for (int i=0;i<infos.Length;i++)
       // {
            
       //     int info = (int)Mathf.Sqrt(infos.Length);

       //     //string oldname =  files[i].Replace(@"\\",@"\");

       //     //string newname = newFilePath + @"\" + tianjiaString + infos[i].Name;
       //     string newname = newFilePath + @"\" + tianjiaString + i / info + "_" + i % info+".jpg";
       //     //File.Move(oldname, newname);
       //     File.Move(files[i], newname);
       //     //file.MoveTo(FilePath + @"\\" + newname);
       // }

  //  }

    // Update is called once per frame
    void Update () {
	
	}
    //public static FileStream Open(string path, FileMode mode)

}
